// https://leetcode.cn/problems/x-of-a-kind-in-a-deck-of-cards/
// Created by ade on 2022/8/22.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>


using namespace std;

class Solution {
public:
    bool hasGroupsSizeX(vector<int> &deck) {
        unordered_map<int, int> m = {};
        for (auto i : deck) {
            m[i]++;
        }
        int minNum = 10000;
        for (auto i : m) {
            minNum = min(minNum, i.second);
        }
        for (int i = 2; i <= minNum; i++) {
            int flag = 1;
            for (auto item : m) {
                if (item.second % i != 0) {
                    flag = 0;
                    break;
                }
            }
            if (flag == 1) return true;
        }
        return false;
    }
};

int main() {
    vector<int> nums = {1, 1, 2, 2, 1, 2, 4, 4};
    Solution so;
    cout << so.hasGroupsSizeX(nums) << endl;
    return 0;
}